import { BasicColumn, FormSchema } from '/@/components/Table';
import { DictCodeEnum, getDictItems } from '/@/utils/dict';

// 字典值数据类型字典数据
const dictValueTypeDict = getDictItems(DictCodeEnum.DICT_VALUE_TYPE);

export const columns: BasicColumn[] = [
  {
    title: '字典编码',
    dataIndex: 'code',
    width: 100,
  },
  {
    title: '字典名称',
    dataIndex: 'name',
    width: 130,
  },
  {
    title: '排序',
    dataIndex: 'sort',
    width: 90,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '关键词',
    component: 'Input',
    componentProps: {
      placeholder: '请输入字典名称/编码',
    },
    colProps: { span: 16 },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: 'ID',
    component: 'Input',
    show: false,
  },
  {
    field: 'status',
    label: '状态',
    component: 'Input',
    defaultValue: 1,
    show: false,
  },
  {
    field: 'name',
    label: '字典名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'code',
    label: '字典编码',
    component: 'Input',
    dynamicDisabled: ({ values }) => {
      return !!values.id;
    },
    required: true,
  },
  {
    field: 'valueType',
    label: '数据类型',
    component: 'Select',
    defaultValue: 'string',
    componentProps: {
      options: dictValueTypeDict,
    },
    required: true,
  },
  {
    field: 'sort',
    label: '排序',
    component: 'InputNumber',
    defaultValue: 0,
    required: true,
  },
  {
    field: 'remark',
    label: '备注',
    component: 'InputTextArea',
  },
];

export const subColumns: BasicColumn[] = [
  {
    title: '字典项名称',
    dataIndex: 'name',
    width: 130,
  },
  {
    title: '字典项值',
    dataIndex: 'value',
    width: 100,
  },
  {
    title: '排序',
    dataIndex: 'sort',
    width: 90,
  },
];

export const subSearchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '关键词',
    component: 'Input',
    componentProps: {
      placeholder: '请输入字典名称/编码',
    },
    colProps: { span: 16 },
  },
];

export const subFormSchema: FormSchema[] = [
  {
    field: 'id',
    label: 'ID',
    component: 'Input',
    show: false,
  },
  {
    field: 'valueType',
    label: '数据类型',
    defaultValue: 'string',
    component: 'Input',
    show: false,
  },
  {
    field: 'parentId',
    label: '上级ID',
    component: 'Input',
    show: false,
  },
  {
    field: 'dictCode',
    label: '字典编码',
    component: 'Input',
    componentProps: { disabled: true },
  },
  {
    field: 'name',
    label: '字典项名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'value',
    label: '字典项值',
    component: 'Input',
    required: true,
  },
  {
    field: 'color',
    label: '样式颜色',
    component: 'Input',
  },
  {
    field: 'sort',
    label: '排序',
    component: 'InputNumber',
    defaultValue: 0,
    required: true,
  },
  {
    field: 'remark',
    label: '备注',
    component: 'InputTextArea',
  },
];
